package com.boot.security.server.tasks;

import com.boot.security.server.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务
 * @author Administrator
 */
@Component
@Slf4j
public class Tasks {

    @Autowired
    private MailService mailService;

    /**
     * 定时发邮件
     */
    @Scheduled(cron = "0 30 8 * * ? ")
    public void taskMail () {
        mailService.sendMail();
        log.info(new Date() + ": 邮件定时任务！");
    }

    /**
     * 定时查询发送失败小于5次的邮件并重新发送
     */
    @Scheduled(cron = "0 0/5 8-9 * * ?")
    public void inquirySending () {
        mailService.inquirySending();
        log.info(new Date() + ": 定时查询发送失败小于5次的邮件并重新发送定时任务！");
    }
}
